#ifndef SERIAL_CONTROL_C_H
#define SERIAL_CONTROL_C_H

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Initialize serial control and return handle
 * 
 * @param port Serial port path (e.g., "/dev/ttyUSB0")
 * @param baudrate Baud rate (e.g., 115200)
 * @param timeout Timeout in milliseconds
 * @return Opaque handle to serial control instance or NULL on failure
 */
void* serial_control_init(const char* port, int baudrate, int timeout);

/**
 * Set the move time for the arm motion
 * 
 * @param handle Serial control handle
 * @param move_time_ms Time in milliseconds for the motion to complete
 */
void serial_control_set_move_time(void* handle, int move_time_ms);

/**
 * Send joint command with radian values
 * 
 * @param handle Serial control handle
 * @param rads Array of joint angles in radians
 * @param count Number of joint angles
 * @param machine Machine type (e.g., "arm")
 * @return 1 on success, 0 on failure
 */
int serial_control_send_joint_command(void* handle, const double* rads, int count, const char* machine);

/**
 * Get current radian data from the arm
 * 
 * @param handle Serial control handle
 * @param machine Machine type (e.g., "arm")
 * @param rads_out Output array to store joint angles (must be pre-allocated)
 * @param count Maximum number of angles to read
 * @return Number of joints read or -1 on error
 */
int serial_control_get_rads_data(void* handle, const char* machine, double* rads_out, int count);

/**
 * Close serial connection and clean up resources
 * 
 * @param handle Serial control handle
 */
void serial_control_close(void* handle);

/**
 * Recover force on the arm
 * 
 * @param handle Serial control handle
 * @param machine Machine type (e.g., "arm")
 */ 
void serial_control_recover_force(void* handle, const char* machine);

/**
 * Release force on the arm
 * 
 * @param handle Serial control handle
 * @param machine Machine type (e.g., "arm")
 */
void serial_control_release_force(void* handle, const char* machine);

#ifdef __cplusplus
}
#endif

#endif /* SERIAL_CONTROL_C_H */